package hihocoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;
import java.util.TreeSet;

/**
 * 
 */

/**
 * @author zhongfang
 *
 */
public class 可疑的记录 {

	static class Node{
		int child;
		int parent;
		int index;//行号
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner scanner=new Scanner(System.in);
		int N=scanner.nextInt();
		HashMap<Integer, ArrayList<Integer>> child2Parent=new HashMap<>(N);
		TreeSet<Integer> treeSet=new TreeSet<>();
		for (int i = 0; i < N; i++) {
			int a=scanner.nextInt();
			int b=scanner.nextInt();
			if(b==1){//子节点编号不可能为1
				treeSet.add(i+1);
				continue;
			}
			if(child2Parent.containsKey(b)){
				child2Parent.get(b).add(i+1);
			}else {
				ArrayList<Integer> list=new ArrayList<>();
				list.add(i+1);
				child2Parent.put(b, list);
			}
		}
		for (ArrayList<Integer> list : child2Parent.values()) {
			if(list.size()>1){
				treeSet.addAll(list);
			}
		}
		for (Integer integer : treeSet) {
			System.out.print(integer+" ");
		}
	}

}
